
package ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.bumptech.glide.request.RequestOptions;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Bean.AllyBean;
import activity.glide.GlideApp;
import base.BaseViewHolder;
import base.SuperBaseAdapter;


/**
 * 合伙人适配器
 * Created by chenjian on 19/2/27.
 */
public class PartnerAdapter extends SuperBaseAdapter<AllyBean.DataBean.ItemsBean> {

    List<AllyBean.DataBean.ItemsBean> mData = new ArrayList<>();
    Context mContext;
    private boolean mShowLevel;

    private String mSearchtype = "0";

    public PartnerAdapter(Context context, List<AllyBean.DataBean.ItemsBean> data, String searchtype, boolean isShow) {
        super(context, data);
        mContext = context;
        mData = data;
        mShowLevel = isShow;
        mSearchtype = searchtype;
    }

    public void setSearchtype(String type) {
        mSearchtype = type;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder holder, final AllyBean.DataBean.ItemsBean item, final int position) {
        ImageView bg = holder.getView(R.id.f_a1_img1);
        ImageView level = holder.getView(R.id.level);
        GlideApp.with(mContext)
                .load(item.getBankBackImgPath())
                .error(R.drawable.photo)
                .placeholder(R.drawable.photo)
                .apply(RequestOptions.circleCropTransform())
                .into(bg);
        TextView realName = holder.getView(R.id.f_a1_txt1);
        TextView sortInfo = holder.getView(R.id.f_a1_txt2);
        realName.setText(item.getRealName());
        if (mSearchtype.equals("0")) {
            sortInfo.setVisibility(View.GONE);
        } else if (mSearchtype.equals("1")) {
            sortInfo.setVisibility(View.VISIBLE);
            sortInfo.setText("共" + item.getAllyCount() + "位合伙人");
        } else if (mSearchtype.equals("2")) {
            sortInfo.setVisibility(View.VISIBLE);
            sortInfo.setText(item.getCurrTrans().getTotalAmount() + "万元");
        } else if (mSearchtype.equals("3")) {
            sortInfo.setVisibility(View.VISIBLE);
            sortInfo.setText("激活" + item.getMerchantCount() + "户");
        }
        if (item.currTrans != null) {
            switch (item.getCurrTrans().getLevelAmount()) {
                case 1:
                    level.setBackgroundResource(R.mipmap.r1);
                    break;
                case 2:
                    level.setBackgroundResource(R.mipmap.r2);
                    break;
                case 3:
                    level.setBackgroundResource(R.mipmap.r3);
                    break;
                case 4:
                    level.setBackgroundResource(R.mipmap.r4);
                    break;
                case 5:
                    level.setBackgroundResource(R.mipmap.r5);
                    break;
                case 6:
                    level.setBackgroundResource(R.mipmap.r6);
                    break;
                case 7:
                    level.setBackgroundResource(R.mipmap.r7);
                    break;
                case 8:
                    level.setBackgroundResource(R.mipmap.r8);
                    break;
                case 9:
                    level.setBackgroundResource(R.mipmap.r9);
                    break;
                case 10:
                    level.setBackgroundResource(R.mipmap.r10);
                    break;
                case 11:
                    level.setBackgroundResource(R.mipmap.r11);
                    break;
                case 12:
                    level.setBackgroundResource(R.mipmap.r12);
                    break;
                default:
                    break;

            }
        } else {
            level.setBackgroundResource(R.mipmap.r1);
        }
        level.setVisibility(mShowLevel ? View.VISIBLE : View.GONE);

        holder.getView(R.id.f_a1_rela).setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + item.getPhoneNumber()));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        });
    }


    @Override
    protected int getItemViewLayoutId(int position, AllyBean.DataBean.ItemsBean item) {
        return R.layout.fragment1_allyadapter_item;
    }

}
